package tree;

import java.util.ArrayList;

public class MinDepth {
    public static void main(String[] args) {
        TreeNodec two = new TreeNodec(2, null, null);
        TreeNodec three = new TreeNodec(null, null, null);
        TreeNodec one = new TreeNodec(1, two, three);

    }
    public int minDepth(TreeNodec root) {
        int depth = 1;
        ArrayList<TreeNodec> queue = new ArrayList<>();
        queue.add(root);
        a:while (!queue.isEmpty()){
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                TreeNodec pop = queue.remove(0);
                if(pop.left == null && pop.right == null) break a;
                if (pop.left != null) queue.add(pop.left);
                if (pop.right != null) queue.add(pop.right);
            }
            depth++;
        }
        return depth;
    }
}
